package person.bing.fbcloud.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import person.bing.fbcloud.api.entity.PostComment;
import person.bing.fbcloud.mapper.PostCommentMapper;
import person.bing.fbcloud.service.PostCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 评论表 服务实现类
 * </p>
 *
 * @author mengfb
 * @since 2020-12-08
 */
@Service
public class PostCommentServiceImpl extends ServiceImpl<PostCommentMapper, PostComment> implements PostCommentService {

    @Override
    public List<PostComment> getPostComment(String postId) {
        List<PostComment> postComments = this.list(Wrappers.<PostComment>query().lambda()
                .eq(PostComment::getPostId, postId)
        );
        return postComments;
    }

    @Override
    public void addPostComment(String comment, String userCode, String postId) {
        LocalDateTime now = LocalDateTime.now();
        PostComment postComment = new PostComment();
        postComment.setComment(comment);
        postComment.setCreateTime(now);
        postComment.setUpdateTime(now);
        postComment.setPostId(postId);
        postComment.setUserCode(userCode);
        this.save(postComment);
    }
}
